606 二維串列行列數
def compute(rows,cols): for i in range(rows): for j in range(cols): print("%4d" %(j-i), end="") print("") rows = int(input().strip()) cols = int(input().strip()) compute(rows,cols)
710 詞典搜尋
methond 1diction = {} while True: key = input("Key: ").strip() if key == "end": break value = input("Value: ").strip() diction[key] = value search_key = input("Search key: ").strip() print(search_key in diction)
methond 2
value={} while True: key = input("Key: ").strip() if key=="end": break value[key]=input("Value: ").strip() sck=input("Search key: ").strip() print(sck in value.keys())
807 字串加總
list1 = input().strip().split(" ") total = 0 for i in range(len(list1)): total += int(list1[i]) average = total/(len(list1)) print("Total = %d" %total) print("Average = %.1f" %average)
參考資料:TQC+ Python 3